﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using IosDatamodel;
using System.IO;
using IOSpro.Lib;
using IOSpro.Models;
namespace IOSpro
{
    /// <summary>
    /// Summary description for WebService1
    /// </summary>
    [WebService(Namespace = "http://175.102.32.44:8080/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class WebService1 : System.Web.Services.WebService
    {
        private IosDBEntities db;
        private IVideosBL iblvideos;
        private ICommentsBL iblcomment;
        private IVideosheetBL iblvideosheet;
        public WebService1() 
        {
            db = new IosDBEntities();
            iblvideos = new VideosBL();
            iblcomment = new CommentsBL();
            iblvideosheet = new VideosheetBL();
        }
        public class videoinfo1 {

            public int Id;
            public string VideoIssue;
            public string VideoTitle;
            public string VideoImage;
            public string VideoIntroduction;      
        }


        public class VideoComments
        {

           
            public string Email ;
            public string UserComment;
            public int VideoId;
            public DateTime CommentDate;
        }

        public class ShowVideoSheet
        {
            public int Id;
            public string image;
            public string name;
            public string text;
            public string videourlname;
     
        }
        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }

        [WebMethod]
        public int add(int x,int y)
        {
            return x+y;
        }

        [WebMethod]
    //    [System.Xml.Serialization.XmlInclude(typeof(Videos))]
        public List<videoinfo1> VideoIndex(int videosheetId)
        {
            List<videoinfo1> aa = new List<videoinfo1>();
            var videos = from n in db.Videos where n.VideoSheetId==videosheetId select n;

            foreach( var vv in videos){
                var tt = new videoinfo1();
              tt.Id = vv.Id;
              tt.VideoIssue = vv.VideoIssue;
              tt.VideoTitle = vv.VideoTitle;
              tt.VideoImage = vv.VideoImage;
              tt.VideoIntroduction = vv.VideoIntroduction;
              aa.Add(tt);        
            }

         //   aa=videos as IQueryable<Videos> as List<Videos>;
            return  aa;
        }

  //[WebMethod]
  //      public List<VideoSheet> VideoSheetIndex()
  //      {
  //          List<VideoSheet> aa = new List<VideoSheet>();
  //          var videosheet = from n in db.VideoSheet select n;

  //          foreach (var vv in videosheet)
  //          {
  //              var tt = new VideoSheet();
  //              tt.Id = vv.Id;
  //              tt.image = vv.Image;
  //              tt.name = vv.Name;
  //              aa.Add(tt);
  //          }

  //          //   aa=videos as IQueryable<Videos> as List<Videos>;
  //          return aa;
  //      }





        [WebMethod]
        public List<VideoComments> VideoCommentsIndex(int videoId)
        {
            List<VideoComments> aa = new List<VideoComments>();
            var videocomments = iblcomment.GetcommentsList(Convert.ToInt32(videoId));

            foreach (var vv in videocomments)
            {
                var tt = new VideoComments();
                tt.VideoId = vv.VideoId;
                tt.CommentDate = vv.CommentDate;
                tt.Email = vv.Email;
                tt.UserComment = vv.UserComment;
                aa.Add(tt);
            }

            //   aa=videos as IQueryable<Videos> as List<Videos>;
            return aa;
        }

  [WebMethod]
  public List<ShowVideoSheet> ShowVideoSheetlist()
  {
      List<ShowVideoSheet> aa = new List<ShowVideoSheet>();
      var videosheet = iblvideosheet.GetAllVideosheetInfo();

      foreach (var vv in videosheet)
      {
          var tt = new ShowVideoSheet();
          tt.Id = vv.Id;
          tt.name = vv.Name;
          tt.image = vv.Image;
          tt.text = vv.Text;
          tt.videourlname = vv.VideoUrlName;
          aa.Add(tt);
      }

      //   aa=videos as IQueryable<Videos> as List<Videos>;
      return aa;
  }


    }
}
